package com.lai.hospital.controller;

import com.lai.hospital.service.DepartmentService;
import com.lai.hospital.vo.ConditionVO;
import com.lai.hospital.vo.DepartmentVO;
import com.lai.hospital.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author : lai
 * @version V1.0
 * @Project: hospital-springboot
 * @Package com.lai.hospital.controller
 * @Description: 科室控制器
 * @date Date : 2022年11月24日 0:53
 */
@RestController
@Api(value = "科室模块")
public class DepartmentController {

    @Autowired
    private DepartmentService departmentService;


    @GetMapping("/admin/listDepartment")
    @ApiOperation(value = "查看科室列表")
    public Result<?> listDepartment(ConditionVO conditionVO){
        return Result.ok(departmentService.listDepartment(conditionVO));
    }

    @GetMapping("/admin/listDepartmentChildren")
    @ApiOperation(value = "查看子科室列表")
    public Result<?> listDepartmentChildren(){
        return Result.ok(departmentService.listDepartmentChildren());
    }

    @PostMapping("/admin/saveOrUpdateDepartment")
    @ApiOperation(value = "新增或修改科室")
    public Result<?> saveOrUpdateDepartment(@Valid @RequestBody DepartmentVO departmentVO){
        departmentService.saveOrUpdateDepartment(departmentVO);
        return Result.ok();
    }

    @DeleteMapping("/admin/deleteDepartment/{departmentId}")
    @ApiOperation(value = "删除科室")
    public Result<?> deleteDepartment(@PathVariable("departmentId") Integer departmentId){
        departmentService.deleteDepartment(departmentId);
        return Result.ok();
    }

}
